{-# LANGUAGE DeriveDataTypeable   #-}
{-|
    Module      :  Numeric.ER.BasicTypes.PlusMinus
    Description :  mini sign datatype
    Copyright   :  (c) Michal Konecny
    License     :  BSD3

    Maintainer  :  mikkonecny@gmail.com
    Stability   :  experimental
    Portability :  portable
    
    A mini enumeration to represent the sign of different numbers and approximations.
-}
module Numeric.ER.BasicTypes.PlusMinus where

import Data.Typeable
import Data.Generics.Basics
import Data.Binary
--import BinaryDerive

data PlusMinus = Minus | Plus
    deriving (Eq, Ord, Typeable, Data)

instance Show PlusMinus where
    show Plus = "+"
    show Minus = "-"

{- the following has been generated by BinaryDerive -}
instance Binary PlusMinus where
  put Minus = putWord8 0
  put Plus = putWord8 1
  get = do
    tag_ <- getWord8
    case tag_ of
      0 -> return Minus
      1 -> return Plus
      _ -> fail "no parse"
{- the above has been generated by BinaryDerive -}

signNeg Plus = Minus
signNeg Minus = Plus

signMult Plus s = s
signMult Minus s = signNeg s

signToNum Plus = 1
signToNum Minus = -1
